home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / gkismet / NetworkTree.pm < prev    next >
Text File  |  2005-10-20  |  38KB  |  1,389 lines

  1. #!/usr/bin/perl -w
  2. #
  3. # $Id: NetworkTree.pm,v 1.92 2005/04/11 21:58:28 solovam Exp $
  4. #
  5. # This file is a part of gkismet
  6. #
  7. # This program is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU General Public License
  9. # as published by the Free Software Foundation; either version 2
  10. # of the License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20. #
  21.  
  22. #
  23. # NetworkTree class
  24. #
  25. package NetworkTree;
  26.  
  27. use Gtk;
  28. use strict;
  29. use Misc;
  30. use Observable;
  31. use ReusableConnObserver;
  32.  
  33. @NetworkTree::ISA = qw(Observable ReusableConnObserver);
  34.  
  35. my %network_type = (network_ap => 0, network_adhoc => 1, network_probe => 2, network_turbocell => 3, network_data => 4, network_remove => 5);
  36. my %address_type = (address_none => 0, address_factory => 1, address_udp => 2, address_arp => 3, address_tcp => 4, address_dhcp => 5, address_group => 6);
  37. my %carrier_type = (carrier_unknown => 0, carrier_80211b => 1, carrier_80211bplus => 2, carrier_80211a => 3, carrier_80211g => 4,
  38.     carrier_80211fhss => 5, carrier_80211dsss => 6);
  39. my %client_type = (client_unknown => 0, client_fromds => 1, client_tods => 2, client_interds => 3, client_established => 4);
  40. my %encoding_type = (encoding_unknown => 0, encoding_cck => 1, encoding_pbcc => 2, encoding_ofdm => 3);
  41. my %encryption_type = (encryption_none => 0, encryption_unknown => 1, encryption_wep => 2, encryption_layer3 => 4, encryption_wpa => 64,
  42.     encryption_leap => 128, encryption_ttls => 256, encryption_tls => 512, encryption_peap => 1024, encryption_isakmp => 2048, encryption_pptp => 4096);
  43. my $max_manuf_score = 8;
  44. my $timerTimeout = 1000;
  45. my $activeTimeout = 5;
  46. my %networkFieldType = (channel => 'num', firsttime => 'num', lasttime => 'num', datapackets => 'num', signal => 'num', bssid => 'str',
  47.     ssid => 'str', wep => 'str');
  48. my %clientFieldType = (firsttime => 'num', lasttime => 'num', datapackets => 'num', signal => 'num', mac => 'str', wep => 'str');
  49.  
  50. #
  51. # Constructor
  52. #
  53. sub new
  54. {
  55.     my $type = shift;
  56.     my $self = new ReusableConnObserver(@_);
  57.     bless $self, $type;
  58.  
  59.     # Create ctree
  60.     $self->{'ctree'} = new Gtk::CTree(3, 0);
  61.     $self->{'ctree'}->set_column_auto_resize(0, $true);
  62.     $self->{'ctree'}->set_column_auto_resize(1, $true);
  63.     $self->{'ctree'}->set_line_style('dotted');
  64.     $self->{'ctree'}->set_indent(15); 
  65.     $self->{'ctree'}->set_spacing(5);
  66.     $self->{'ctree'}->set_selection_mode(1);
  67.     $self->{'ctree'}->set_column_visibility(2, $false);
  68.     $self->{'ctree'}->set_sort_column(2);
  69.     $self->{'ctree'}->set_compare_func(sub {$self->compare(@_)});
  70.     $self->{'ctree'}->signal_connect('tree_select_row', sub {$self->selectHandler(@_)});
  71.     $self->{'ctree'}->signal_connect('tree_unselect_row', sub {$self->selectHandler(@_)});
  72.     $self->{'ctree'}->show();
  73.  
  74.     # Read manufacturers data
  75.     $self->{'apManuf'} = $self->readManufData($self->{'gKismetApplication'}{'path'}{'etc'} . '/ap_manuf');
  76.     $self->{'clManuf'} = $self->readManufData($self->{'gKismetApplication'}{'path'}{'etc'} . '/client_manuf');
  77.  
  78.     # Get colors
  79.         $self->buildColors();
  80.  
  81.     # Ask to notify us of the preferences changes
  82.     $self->{'gKismetApplication'}->{'preferences'}->addObserver($self);
  83.  
  84.     # Popup menu
  85.     my @menuItems =
  86.     (
  87.                 {path => '/Expand', callback => sub {$self->expand()}},
  88.                 {path => '/Collapse', callback => sub {$self->collapse()} },
  89.                 {path => '/Packet Dump', callback => sub {$self->{'gKismetApplication'}->bssObserverOpenSelected('PacketWindow')}},
  90.                 {path => '/String Dump', callback => sub {$self->{'gKismetApplication'}->bssObserverOpenSelected('StringWindow')}},
  91.                 {path => '/Locator', callback => sub {$self->{'gKismetApplication'}->bssObserverOpenSelected('Locator')}},
  92.         {path => '/Sort', type  => '<Branch>'},
  93.         {path => '/Sort/Ascending', callback  => sub {$self->setSortOrder('ascending')}},
  94.         {path => '/Sort/Descending', callback => sub {$self->setSortOrder('descending')}},
  95.         {path => '/Sort Networks', type  => '<Branch>'},
  96.         {path => '/Sort Networks/By channel', callback => sub {$self->setNetworksSortBy('channel')}},
  97.         {path => '/Sort Networks/By first seen', callback => sub {$self->setNetworksSortBy('firsttime')}},
  98.         {path => '/Sort Networks/By last seen', callback => sub {$self->setNetworksSortBy('lasttime')}},
  99.         {path => '/Sort Networks/By BSSID', callback => sub {$self->setNetworksSortBy('bssid')}},
  100.         {path => '/Sort Networks/By SSID', callback => sub {$self->setNetworksSortBy('ssid')}},
  101.         {path => '/Sort Networks/By data packet count', callback => sub {$self->setNetworksSortBy('datapackets')}},
  102.         {path => '/Sort Networks/By signal power', callback => sub {$self->setNetworksSortBy('signal')}},
  103.         {path => '/Sort Networks/By WEP', callback => sub {$self->setNetworksSortBy('wep')}},
  104.         {path => '/Sort Clients', type  => '<Branch>'},
  105.         {path => '/Sort Clients/By first seen', callback => sub {$self->setClientsSortBy('firsttime')}},
  106.         {path => '/Sort Clients/By last seen', callback => sub {$self->setClientsSortBy('lasttime')}},
  107.         {path => '/Sort Clients/By MAC', callback => sub {$self->setClientsSortBy('mac')}},
  108.         {path => '/Sort Clients/By data packet count', callback => sub {$self->setClientsSortBy('datapackets')}},
  109.         {path => '/Sort Clients/By signal power', callback => sub {$self->setClientsSortBy('signal')}},
  110.         {path => '/Sort Clients/By WEP', callback => sub {$self->setClientsSortBy('wep')}},
  111.     );
  112.     my $accelGroup = new Gtk::AccelGroup();
  113.     my $itemFactory = new Gtk::ItemFactory('Gtk::Menu', '<main>', $accelGroup);
  114.     $itemFactory->create_items(@menuItems);
  115.     my $popup = $itemFactory->get_widget('<main>');
  116.     $popup->show_all();
  117.     $self->{'popup'} = $popup;
  118.     $self->{'ctree'}->signal_connect('button_press_event', sub {$self->buttonPressHandler(@_)});
  119.  
  120.     # Sorting
  121.     $self->{'ctree'}->set_sort_type(0);
  122.     $self->{'networksSortBy'} = 'firsttime';
  123.     $self->{'clientsSortBy'} = 'firsttime';
  124.  
  125.     # Set timer
  126.     Gtk->timeout_add($timerTimeout, sub {$self->timerHandler()});
  127.  
  128.     # Pixmaps
  129.     $self->{'pixmapsBuilt'} = $false;
  130.  
  131.     # Standard
  132.     return $self;
  133. }
  134.  
  135. #
  136. # Set sorting order
  137. #
  138. sub setSortOrder
  139. {
  140.     my $self = shift;
  141.     my $order = shift;
  142.     if($order eq 'ascending')
  143.     {
  144.         $self->{'ctree'}->set_sort_type(0);
  145.     }
  146.     else
  147.     {
  148.         $self->{'ctree'}->set_sort_type(1);
  149.     }
  150.     $self->{'ctree'}->freeze();
  151.     $self->{'ctree'}->sort_recursive(undef);
  152.     $self->{'ctree'}->thaw();
  153. }
  154.  
  155. #
  156. # Handle tinmer event
  157. #
  158. sub timerHandler
  159. {
  160.     my $self = shift;
  161.  
  162.     if(!defined $self->{'connection'})
  163.     {
  164.         return $true;
  165.     }
  166.  
  167.     $self->{'ctree'}->freeze();
  168.     for my $bssid (keys %{$self->{'cnode'}})
  169.     {
  170.         my @info = $self->{'ctree'}->get_node_info($self->{'cnode'}{$bssid}{'node'});
  171.         $self->{'ctree'}->set_node_info($self->{'cnode'}{$bssid}{'node'},
  172.             $self->getNetworkFieldValue($bssid, 'SSID'), 5,
  173.             $self->{'pixmap'}{$self->getNetworkPixmapName($bssid)}{'pixmap'},
  174.             $self->{'pixmap'}{$self->getNetworkPixmapName($bssid)}{'mask'},
  175.             $self->{'pixmap'}{$self->getNetworkPixmapName($bssid)}{'pixmap'},
  176.             $self->{'pixmap'}{$self->getNetworkPixmapName($bssid)}{'mask'},
  177.             $false, $info[7]);
  178.         $self->{'ctree'}->node_set_foreground($self->{'cnode'}{$bssid}{'node'}, $self->getNetworkColor($bssid));
  179.         for my $mac (keys %{$self->{'cnode'}{$bssid}{'client'}})
  180.         {
  181.             my @info = $self->{'ctree'}->get_node_info($self->{'cnode'}{$bssid}{'client'}{$mac}{'node'});
  182.             $self->{'ctree'}->set_node_info($self->{'cnode'}{$bssid}{'client'}{$mac}{'node'},
  183.                 $self->getClientFieldValue($bssid, $mac, 'MAC'), 5,
  184.                 $self->{'pixmap'}{$self->getClientPixmapName($bssid, $mac)}{'pixmap'},
  185.                 $self->{'pixmap'}{$self->getClientPixmapName($bssid, $mac)}{'mask'},
  186.                 $self->{'pixmap'}{$self->getClientPixmapName($bssid, $mac)}{'pixmap'},
  187.                 $self->{'pixmap'}{$self->getClientPixmapName($bssid, $mac)}{'mask'},
  188.                 $false, $info[7]);
  189.         }
  190.     }
  191.     if($self->{'gKismetApplication'}{'preferences'}->getPref('keepSorted'))
  192.     {
  193.         $self->sortUpdated();
  194.     }
  195.     $self->{'ctree'}->thaw();
  196.     return $true;
  197. }
  198.  
  199. #
  200. # Sort updated items in ctree
  201. #
  202. sub sortUpdated
  203. {
  204.     my $self = shift;
  205.  
  206.     if(!defined $self->{'connection'})
  207.     {
  208.         return;
  209.     }
  210.  
  211.     if($self->{'networkUpdateFlag'})
  212.     {
  213.         $self->{'ctree'}->sort(undef);
  214.     }
  215.     $self->{'networkUpdateFlag'} = $false;
  216.  
  217.     for my $bssid (keys %{$self->{'cnode'}})
  218.         {
  219.         if($self->{'clientUpdateFlag'}{$bssid})
  220.         {
  221.             $self->{'ctree'}->sort($self->{'cnode'}{$bssid}{'node'});
  222.         }
  223.         $self->{'clientUpdateFlag'}{$bssid} = $false;
  224.     }
  225. }
  226.  
  227. #
  228. # Change network sorting
  229. #
  230. sub setNetworksSortBy
  231. {
  232.     my $self = shift;
  233.     my $networksSortBy = shift;
  234.     $self->{'ctree'}->freeze();
  235.     $self->{'networksSortBy'} = $networksSortBy;
  236.     $self->{'ctree'}->sort_recursive(undef);
  237.     $self->{'ctree'}->thaw();
  238. }
  239.  
  240. #
  241. # Change client sorting
  242. #
  243. sub setClientsSortBy
  244. {
  245.     my $self = shift;
  246.     my $clientsSortBy = shift;
  247.     $self->{'ctree'}->freeze();
  248.     $self->{'clientsSortBy'} = $clientsSortBy;
  249.     $self->{'ctree'}->sort_recursive(undef);
  250.     $self->{'ctree'}->thaw();
  251. }
  252.  
  253. #
  254. # Handle selection changes
  255. #
  256. sub selectHandler
  257. {
  258.     my $self = shift;
  259.     $self->notifyObservers({'changed' => 'selection'});
  260. }
  261.  
  262. #
  263. # Comparison function for CTree
  264. #
  265. sub compare
  266. {
  267.     my $self = shift;
  268.     my $ctree = shift;
  269.     my $text1= shift;
  270.     my $text2 = shift;
  271.  
  272.     if(!defined $self->{'connection'})    
  273.     {
  274.         return 0;
  275.     }
  276.  
  277.     my $network = $self->{'connection'}->getNetwork();
  278.  
  279.     my($nodeType1, $bssid1, $mac1) = split /,/, $text1;
  280.     my($nodeType2, $bssid2, $mac2) = split /,/, $text2;
  281.  
  282.     if($nodeType1 eq 'networkNode' && $nodeType2 eq 'networkNode')
  283.     {
  284.         if($networkFieldType{$self->{'networksSortBy'}} eq 'num')
  285.         {
  286.             return $network->{$bssid1}{$self->{'networksSortBy'}} <=> $network->{$bssid2}{$self->{'networksSortBy'}};
  287.         }
  288.         elsif($networkFieldType{$self->{'networksSortBy'}} eq 'str')
  289.         {
  290.             return $network->{$bssid1}{$self->{'networksSortBy'}} cmp $network->{$bssid2}{$self->{'networksSortBy'}};
  291.         }
  292.     }
  293.     elsif ($nodeType1 eq 'clientNode' && $nodeType2 eq 'clientNode')
  294.     {
  295.         if($clientFieldType{$self->{'clientsSortBy'}} eq 'num')
  296.         {
  297.             return $network->{$bssid1}{'client'}{$mac1}{$self->{'clientsSortBy'}} <=> $network->{$bssid2}{'client'}{$mac2}{$self->{'clientsSortBy'}};
  298.         }
  299.         elsif($clientFieldType{$self->{'clientsSortBy'}} eq 'str')
  300.         {
  301.             return $network->{$bssid1}{'client'}{$mac1}{$self->{'clientsSortBy'}} cmp $network->{$bssid2}{'client'}{$mac2}{$self->{'clientsSortBy'}};
  302.         }
  303.     }
  304.  
  305.     return 0;
  306. }
  307.  
  308. #
  309. # Button press handler
  310. #
  311. sub buttonPressHandler
  312. {
  313.     my $self = shift;
  314.     my $ctree = shift;
  315.     my $event = shift;
  316.  
  317.     if($event->{'button'} == 3)
  318.     {
  319.         my($row, $column) = $ctree->get_selection_info($event->{'x'}, $event->{'y'});
  320.         if(defined $row && defined $column)
  321.         {
  322.             $ctree->select_row($row, $column);
  323.             $self->{'popup'}->popup(undef, undef, $event->{'time'}, $event->{'button'}, undef, undef);
  324.             return $true;
  325.         }
  326.     }
  327.     return $false;
  328. }
  329.  
  330. #
  331. # Read manufacturers data from files
  332. #
  333. sub readManufData
  334. {
  335.     my $self = shift;
  336.     my $file = shift;
  337.     my @manuf;
  338.     my @fieldNames = qw(mac mask name model ssid chan ip);
  339.  
  340.     open(FILE, $file) or die "Can't open $file: $!\n";
  341.     while(<FILE>)
  342.     {
  343.         chomp;
  344.         my @fields = split '\t', $_;
  345.         splice(@fields, 0, 1, split '\/', $fields[0]); 
  346.         my %m;
  347.         for(my $i = 0; $i <= $#fields; $i++)
  348.         {
  349.             $m{$fieldNames[$i]} = $fields[$i];
  350.         }
  351.         push @manuf, \%m;
  352.     }
  353.     close(FILE);
  354.     return(\@manuf);
  355. }
  356.  
  357. #
  358. # Lookup manufacturer. Very messy.
  359. #
  360. sub lookupManuf
  361. {
  362.     my $self = shift;
  363.     my($manufData, $mac, $ssid, $chan, $wep, $cloaked, $ip)  = (@_);
  364.  
  365.     # Is it cached?
  366.     if(defined $self->{'manufLookupCache'}{$manufData}{$mac}{$ssid}{$chan}{$wep}{$cloaked}{$ip})
  367.     {
  368.         return($self->{'manufLookupCache'}{$manufData}{$mac}{$ssid}{$chan}{$wep}{$cloaked}{$ip}{'name'},
  369.         $self->{'manufLookupCache'}{$manufData}{$mac}{$ssid}{$chan}{$wep}{$cloaked}{$ip}{'model'},
  370.         $self->{'manufLookupCache'}{$manufData}{$mac}{$ssid}{$chan}{$wep}{$cloaked}{$ip}{'score'})
  371.     }
  372.  
  373.     # First build list of matching entries
  374.     my @matching;
  375.     my $bestMaskLen = 0;
  376.     for my $m (@{$manufData})
  377.     {
  378.         if($self->macAnd($m->{'mask'}, $mac) eq $m->{'mac'})
  379.         {
  380.             my $maskLen = $self->maskLen($m->{'mask'});
  381.             if($maskLen > $bestMaskLen)
  382.             {
  383.                 $bestMaskLen = $maskLen;
  384.                 @matching = ();
  385.             }
  386.             push @matching, $m;
  387.         }
  388.     }
  389.  
  390.     # If no matches, return unknowns
  391.     if($#matching < 0)
  392.     {
  393.         $self->{'manufLookupCache'}{$manufData}{$mac}{$ssid}{$chan}{$wep}{$cloaked}{$ip} = {name => 'Unknown', model => 'Unknown', score => 0};
  394.         return('Unknown', 'Unknown', 0);
  395.     }
  396.  
  397.     # Select matches where ssid and channel match
  398.     my $bestScore = 5;
  399.     my $bestMatch = $matching[0];
  400.     for my $m (@matching)
  401.     {
  402.         my $score = 5;
  403.         if(defined $m->{'ssid'} && $m->{'ssid'} eq $ssid)
  404.         {
  405.             $score += 1;
  406.         }
  407.         if(defined $m->{'chan'} && $m->{'chan'} == $chan)
  408.         {
  409.             $score += 1;
  410.         }
  411.         if(defined $m->{'ip'} && $m->{'ip'} eq $ip)
  412.         {
  413.             $score += 1;
  414.         }
  415.         if($score > $bestScore)
  416.         {
  417.             $bestMatch = $m;
  418.         }
  419.         $bestScore = $score;
  420.     }
  421.  
  422.     # Reduce score if wep of cloaking present
  423.     if($bestMatch->{'wep'})
  424.     {
  425.         $bestScore -= 1;
  426.     }
  427.     if($bestMatch->{'cloaked'})
  428.     {
  429.         $bestScore -= 1;
  430.     }
  431.  
  432.     # Update cache
  433.     $self->{'manufLookupCache'}{$manufData}{$mac}{$ssid}{$chan}{$wep}{$cloaked}{$ip} = {name => $bestMatch->{'name'},
  434.         model => $bestMatch->{'model'}, score => $bestScore};
  435.  
  436.     return($bestMatch->{'name'}, $bestMatch->{'model'}, $bestScore);
  437. }
  438.  
  439. #
  440. # Perform logical "and" on MACs
  441. #
  442. sub macAnd
  443. {
  444.     my $self = shift;
  445.     my($a, $b) = (@_);
  446.     my @aOctets = split(':', $a);
  447.     my @bOctets = split(':', $b);
  448.     my @resOctets;
  449.     for(my $i = 0; $i <= 5; $i++)
  450.     {
  451.         $resOctets[$i] = sprintf("%.2X", hex($aOctets[$i]) & hex($bOctets[$i]));
  452.     }
  453.     my $res = join ':', @resOctets;
  454.     return $res;
  455. }
  456.  
  457. #
  458. # Get netmask length
  459. #
  460. sub maskLen
  461. {
  462.     my $self = shift;
  463.     my $mask = shift;
  464.     my @octets = split(':', $mask);
  465.     my $len = 0;
  466.     for(my $i = 0; $i <= 5; $i++)
  467.     {
  468.         my $octet = hex($octets[$i]);
  469.         for(my $j = 0; $j <= 7; $j++)
  470.         {
  471.             if(!$octet)
  472.             {
  473.                 return($len);
  474.             }
  475.             $octet = ($octet << 1);
  476.             $len++;
  477.         }
  478.     }
  479. }
  480.  
  481. #
  482. # Remove all stored data
  483. #
  484. sub flush
  485. {
  486.         my $self = shift;
  487.  
  488.     # Remove all nodes from Ctree
  489.     $self->{'ctree'}->freeze();
  490.     for my $n (keys %{$self->{'cnode'}})
  491.         {
  492.                 if(defined $self->{'cnode'}{$n}{'node'})
  493.                 {
  494.                         $self->{'ctree'}->remove_node($self->{'cnode'}{$n}{'node'});
  495.                 }
  496.         }
  497.     $self->{'ctree'}->thaw();
  498.  
  499.     # Delete cnodes hash
  500.     delete $self->{'cnode'};
  501. }
  502.  
  503. #
  504. # Get widget
  505. #
  506. sub getWidget
  507. {
  508.     my $self = shift;
  509.     return $self->{'ctree'};
  510. }
  511.  
  512. #
  513. # Handle an update from an observer
  514. #
  515. sub update
  516. {
  517.     my $self = shift;
  518.     my $object = shift;
  519.     my $data = shift;
  520.  
  521.     if($object->isa('Connection') && defined $self->{'connection'} && $object eq $self->{'connection'})
  522.     {
  523.         if($data->{'changed'} eq 'network')
  524.         {
  525.             my $bssid = $data->{'bssid'};
  526.             $self->{'networkUpdateFlag'} = $true;
  527.             $self->networkScreenUpdate($bssid);
  528.         }
  529.         elsif($data->{'changed'} eq 'client')
  530.         {
  531.             my $bssid = $data->{'bssid'};
  532.             my $mac = $data->{'mac'};
  533.             $self->{'clientUpdateFlag'}{$bssid} = $true;
  534.             $self->clientScreenUpdate($bssid, $mac);
  535.         }
  536.         elsif($data->{'changed'} eq 'remove')
  537.         {
  538.             my $bssid = $data->{'bssid'};
  539.             $self->networkScreenRemove($bssid);
  540.         }
  541.     }
  542.     elsif($object->isa('Preferences') && defined $self->{'connection'})
  543.     {
  544.         my $network = $self->{'connection'}->getNetwork();
  545.         $self->{'ctree'}->freeze();
  546.         $self->flush();
  547.         for my $bssid (keys %{$network})
  548.         {
  549.             $self->networkScreenUpdate($bssid);
  550.             for my $mac (keys %{$network->{$bssid}{'client'}})
  551.             {
  552.                 $self->clientScreenUpdate($bssid, $mac);
  553.             }
  554.         }
  555.         $self->{'ctree'}->sort_recursive(undef);
  556.         $self->{'ctree'}->thaw();
  557.     }
  558. }
  559.  
  560. #
  561. # Network is updated or added
  562. #
  563. sub networkScreenUpdate
  564. {
  565.     my $self = shift;
  566.     my $bssid = shift;
  567.  
  568.     if(!defined $self->{'connection'})
  569.     {
  570.         return;
  571.     }
  572.  
  573.     $self->{'ctree'}->freeze();
  574.  
  575.     # If there is no network node create it
  576.     if(!defined $self->{'cnode'}{$bssid}{'node'})
  577.     {
  578.         my $n = $self->{'ctree'}->insert_node(undef, undef,
  579.             [$self->getNetworkFieldValue($bssid, 'SSID'), '', "networkNode,$bssid"], 5,
  580.             $self->{'pixmap'}{$self->getNetworkPixmapName($bssid)}{'pixmap'},
  581.             $self->{'pixmap'}{$self->getNetworkPixmapName($bssid)}{'mask'},
  582.             $self->{'pixmap'}{$self->getNetworkPixmapName($bssid)}{'pixmap'},
  583.             $self->{'pixmap'}{$self->getNetworkPixmapName($bssid)}{'mask'},
  584.             $false, $false);
  585.         $self->{'ctree'}->node_set_foreground($n, $self->getNetworkColor($bssid));
  586.         $self->{'ctree'}->node_set_selectable($n, $true);
  587.         if(!$self->{'ctree'}->selection())
  588.         {
  589.             $self->{'ctree'}->select($n);
  590.         }
  591.         $self->{'cnode'}{$bssid}{'node'} = $n;
  592.     }
  593.     # Otherwise update it
  594.     else
  595.     {
  596.         my @info = $self->{'ctree'}->get_node_info($self->{'cnode'}->{$bssid}{'node'});
  597.         $self->{'ctree'}->set_node_info($self->{'cnode'}{$bssid}{'node'},
  598.             $self->getNetworkFieldValue($bssid, 'SSID'), 5,
  599.             $self->{'pixmap'}{$self->getNetworkPixmapName($bssid)}{'pixmap'},
  600.             $self->{'pixmap'}{$self->getNetworkPixmapName($bssid)}{'mask'},
  601.             $self->{'pixmap'}{$self->getNetworkPixmapName($bssid)}{'pixmap'},
  602.             $self->{'pixmap'}{$self->getNetworkPixmapName($bssid)}{'mask'},
  603.             $false, $info[7]);
  604.         $self->{'ctree'}->node_set_foreground($self->{'cnode'}{$bssid}{'node'}, $self->getNetworkColor($bssid));
  605.     }
  606.  
  607.     # Loop through network fields
  608.     for my $f ($self->{'gKismetApplication'}{'preferences'}->getPref('networkFieldNames'))
  609.     {
  610.         # If the field is shown
  611.         if($self->{'gKismetApplication'}{'preferences'}->getPref('networkFieldStatus', $f))
  612.         {
  613.             # If the field node is not defined create it
  614.             if(!defined $self->{'cnode'}{$bssid}{$f}{'node'})
  615.             {
  616.                 my $n = $self->{'ctree'}->insert_node($self->{'cnode'}{$bssid}{'node'}, undef,
  617.                     [$f, $self->getNetworkFieldValue($bssid, $f), "networkNodeField,$bssid,$f"], 5,
  618.                     undef, undef, undef, undef, $true, $false); 
  619.                 $self->{'ctree'}->node_set_selectable($n, $false);
  620.                 $self->{'cnode'}{$bssid}{$f}{'node'} = $n;
  621.             }
  622.             # Otherwise update it
  623.             else
  624.             {
  625.                 $self->{'ctree'}->set_text($self->{'cnode'}{$bssid}{$f}{'node'}, 1,
  626.                     $self->getNetworkFieldValue($bssid, $f));
  627.             }
  628.         }
  629.     }
  630.  
  631.     $self->{'ctree'}->thaw();
  632. }
  633.  
  634. #
  635. # Network is deleted
  636. #
  637. sub networkScreenRemove
  638. {
  639.     my $self = shift;
  640.     my $bssid = shift;
  641.  
  642.     if(defined $self->{'cnode'}{$bssid})
  643.     {
  644.         $self->{'ctree'}->remove_node($self->{'cnode'}{$bssid}{'node'});
  645.         delete $self->{'cnode'}{$bssid};
  646.     }
  647. }
  648.  
  649. #
  650. # Client is updated or added
  651. #
  652. sub clientScreenUpdate
  653. {
  654.     my $self = shift;
  655.     my $bssid = shift;
  656.     my $mac = shift;
  657.  
  658.     if(!defined $self->{'connection'})
  659.     {
  660.         return;
  661.     }
  662.  
  663.     # If network node is not defined we can't proceed
  664.     if(!defined $self->{'cnode'}{$bssid})
  665.     {
  666.         return;
  667.     }
  668.  
  669.     $self->{'ctree'}->freeze();
  670.  
  671.     # If client node is not defined create it
  672.     if(!defined $self->{'cnode'}{$bssid}{'client'}{$mac}{'node'})
  673.     {
  674.         my $n = $self->{'ctree'}->insert_node($self->{'cnode'}{$bssid}{'node'}, undef,
  675.             [$self->getClientFieldValue($bssid, $mac, 'MAC'), '', "clientNode,$bssid,$mac"], 5,
  676.             $self->{'pixmap'}{$self->getClientPixmapName($bssid, $mac)}{'pixmap'},
  677.             $self->{'pixmap'}{$self->getClientPixmapName($bssid, $mac)}{'mask'},
  678.             $self->{'pixmap'}{$self->getClientPixmapName($bssid, $mac)}{'pixmap'},
  679.             $self->{'pixmap'}{$self->getClientPixmapName($bssid, $mac)}{'mask'},
  680.             $false, $false);
  681.         $self->{'cnode'}{$bssid}{'client'}{$mac}{'node'} = $n;
  682.         $self->{'ctree'}->node_set_selectable($n, $false);
  683.         $self->networkScreenUpdate($bssid);
  684.     }
  685.     # otherwise update it
  686.     else
  687.     {
  688.         my @info = $self->{'ctree'}->get_node_info($self->{'cnode'}{$bssid}{'client'}{$mac}{'node'});
  689.         $self->{'ctree'}->set_node_info($self->{'cnode'}{$bssid}{'client'}{$mac}{'node'},
  690.             $self->getClientFieldValue($bssid, $mac, 'MAC'), 5,
  691.             $self->{'pixmap'}{$self->getClientPixmapName($bssid, $mac)}{'pixmap'},
  692.             $self->{'pixmap'}{$self->getClientPixmapName($bssid, $mac)}{'mask'},
  693.             $self->{'pixmap'}{$self->getClientPixmapName($bssid, $mac)}{'pixmap'},
  694.             $self->{'pixmap'}{$self->getClientPixmapName($bssid, $mac)}{'mask'},
  695.             $false, $info[7]);
  696.     }
  697.  
  698.     # Loop through client fields
  699.     for my $f ($self->{'gKismetApplication'}{'preferences'}->getPref('clientFieldNames'))
  700.     {
  701.         # If the field is shown
  702.         if($self->{'gKismetApplication'}{'preferences'}->getPref('clientFieldStatus', $f))
  703.         {
  704.             # If the client field is not defined create it
  705.             if(!defined $self->{'cnode'}{$bssid}{'client'}{$mac}{$f}{'node'})
  706.             {
  707.                 my $n = $self->{'ctree'}->insert_node($self->{'cnode'}{$bssid}{'client'}{$mac}{'node'}, undef,
  708.                     [$f, $self->getClientFieldValue( $bssid, $mac, $f), "clientNodeField,$bssid,$mac,$f"], 5,
  709.                     undef, undef, undef, undef, $true, $false);
  710.                 $self->{'cnode'}{$bssid}{'client'}{$mac}{$f}{'node'} = $n;
  711.                 $self->{'ctree'}->node_set_selectable($n, $false);
  712.             }
  713.             # otherwise update it
  714.             else
  715.             {
  716.                 $self->{'ctree'}->set_text($self->{'cnode'}{$bssid}{'client'}{$mac}{$f}{'node'}, 1,
  717.                     $self->getClientFieldValue($bssid, $mac, $f));
  718.             }
  719.         }
  720.     }
  721.  
  722.     $self->{'ctree'}->thaw();
  723. }
  724.  
  725. #
  726. # Get colors
  727. #
  728. sub buildColors
  729. {
  730.     my $self = shift;
  731.     my $colormap = $self->{'ctree'}->get_colormap();
  732.  
  733.     my $colorYellow = Gtk::Gdk::Color->parse_color("gold3");
  734.     $colorYellow = $colormap->color_alloc($colorYellow);
  735.     $self->{'colorYellow'} = $colorYellow;
  736.  
  737.     my $colorGreen = Gtk::Gdk::Color->parse_color("green3");
  738.     $colorGreen = $colormap->color_alloc($colorGreen);
  739.     $self->{'colorGreen'} = $colorGreen;
  740.  
  741.     my $colorRed = Gtk::Gdk::Color->parse_color("red2");
  742.     $colorRed = $colormap->color_alloc($colorRed);
  743.     $self->{'colorRed'} = $colorRed;
  744.  
  745.     my $colorBlack = Gtk::Gdk::Color->parse_color("black");
  746.     $colorBlack = $colormap->color_alloc($colorBlack);
  747.     $self->{'colorBlack'} = $colorBlack;
  748. }
  749.  
  750. #
  751. # Collapse selected nodes
  752. #
  753. sub collapse
  754. {
  755.     my $self = shift;
  756.     my (@selection) = $self->{'ctree'}->selection();
  757.     for my $selected (@selection)
  758.     {
  759.         $self->{'ctree'}->collapse_recursive($selected);
  760.     }
  761. }
  762.  
  763. #
  764. # Expand selected nodes
  765. #
  766. sub expand
  767. {
  768.     my $self = shift;
  769.     my (@selection) = $self->{'ctree'}->selection();
  770.     for my $selected (@selection)
  771.     {
  772.         $self->{'ctree'}->expand_recursive($selected);
  773.     }
  774. }
  775.  
  776. #
  777. # Get selected network bssid
  778. #
  779. sub getSelectedNetworks
  780. {
  781.     my $self = shift;
  782.         my (@selection) = $self->{'ctree'}->selection();
  783.     my @networks;
  784.     for my $selected (@selection)
  785.     {
  786.         my $data = $self->{'ctree'}->node_get_text($selected, 2);
  787.         my @fields = split /,/, $data;
  788.         if($fields[0] eq 'networkNode')
  789.         {
  790.             push @networks, $fields[1];
  791.         }
  792.     }
  793.     return @networks;
  794. }
  795.  
  796. #
  797. # Return printable network data
  798. #
  799. sub getNetworkFieldValue
  800. {
  801.     my $self = shift;
  802.     my $bssid = shift;
  803.     my $field = shift;
  804.  
  805.     if(!defined $self->{'connection'})
  806.     {
  807.         return undef;
  808.     }
  809.     my $network = $self->{'connection'}->getNetwork();
  810.  
  811.     if($field eq 'SSID')
  812.     {
  813.         my $ssid = $network->{$bssid}{'ssid'};
  814.         if($network->{$bssid}{'cloaked'})
  815.         {
  816.             $ssid = '<' . $ssid . '>';
  817.         }
  818.         return $ssid;
  819.     }
  820.     elsif($field eq 'BSSID')
  821.     {
  822.         return $network->{$bssid}{'bssid'};
  823.     }
  824.     elsif($field eq 'Beacon info')
  825.     {
  826.         return $network->{$bssid}{'beaconinfo'};
  827.     }
  828.     elsif($field eq 'Carrier')
  829.     {
  830.         if($network->{$bssid}{'carrierset'} & (1 << $carrier_type{'carrier_unknown'}))
  831.         {
  832.             return 'Unknown';
  833.         }
  834.         elsif($network->{$bssid}{'carrierset'} & (1 << $carrier_type{'carrier_80211b'}))
  835.         {
  836.             return 'IEEE 802.11b';
  837.         }
  838.         elsif($network->{$bssid}{'carrierset'} & (1 << $carrier_type{'carrier_80211bplus'}))
  839.         {
  840.             return 'IEEE 802.11b+';
  841.         }
  842.         elsif($network->{$bssid}{'carrierset'} & (1 << $carrier_type{'carrier_80211a'}))
  843.         {
  844.             return 'IEEE 802.11a';
  845.         }
  846.         elsif($network->{$bssid}{'carrierset'} & (1 << $carrier_type{'carrier_80211g'}))
  847.         {
  848.             return 'IEEE 802.11g';
  849.         }
  850.         elsif($network->{$bssid}{'carrierset'} & (1 << $carrier_type{'carrier_80211fhss'}))
  851.         {
  852.             return 'IEEE 802.11 FHSS';
  853.         }
  854.         elsif($network->{$bssid}{'carrierset'} & (1 << $carrier_type{'carrier_80211dsss'}))
  855.         {
  856.             return 'IEEE 802.11 DSSS';
  857.         }
  858.         else
  859.         {
  860.             return 'Unknown';
  861.         }
  862.     }
  863.     elsif($field eq 'Encoding')
  864.     {
  865.         if($network->{$bssid}{'encodingset'} & (1 << $encoding_type{'encoding_unknown'}))
  866.         {
  867.             return 'Unknown';
  868.         }
  869.         elsif($network->{$bssid}{'encodingset'} & (1 << $encoding_type{'encoding_cck'}))
  870.         {
  871.             return 'CCK';
  872.         }
  873.         elsif($network->{$bssid}{'encodingset'} & (1 << $encoding_type{'encoding_pbcc'}))
  874.         {
  875.             return 'PBCC';
  876.         }
  877.         elsif($network->{$bssid}{'encodingset'} & (1 << $encoding_type{'encoding_ofdm'}))
  878.         {
  879.             return 'OFDM';
  880.         }
  881.         else
  882.         {
  883.             return 'Unknown';
  884.         }
  885.     }
  886.     elsif($field eq 'Manufacturer')
  887.     {
  888.         my($manuf, $model, $score) = $self->lookupManuf(
  889.             $network->{$bssid}{'type'} == $network_type{'network_adhoc'} || $network->{$bssid}{'type'} == $network_type{'network_probe'} ?
  890.             $self->{'clManuf'} : $self->{'apManuf'},
  891.             $bssid, $network->{$bssid}{'ssid'}, $network->{$bssid}{'channel'}, $network->{$bssid}{'wep'}, $network->{$bssid}{'cloaked'},
  892.             $network->{$bssid}{'rangeip'});
  893.         return($manuf);
  894.     }
  895.     elsif($field eq 'Model')
  896.     {
  897.         my($manuf, $model, $score) = $self->lookupManuf(
  898.             $network->{$bssid}{'type'} == $network_type{'network_adhoc'} || $network->{$bssid}{'type'} == $network_type{'network_probe'} ?
  899.             $self->{'clManuf'} : $self->{'apManuf'},
  900.             $bssid, $network->{$bssid}{'ssid'}, $network->{$bssid}{'channel'}, $network->{$bssid}{'wep'}, $network->{$bssid}{'cloaked'},
  901.             $network->{$bssid}{'rangeip'});
  902.         return($model);
  903.     }
  904.     elsif($field eq 'Max rate')
  905.     {
  906.         return $network->{$bssid}{'maxrate'};
  907.     }
  908.     elsif($field eq "Max seen")
  909.     {
  910.         return $network->{$bssid}{'maxseenrate'} * 100;
  911.     }
  912.     elsif($field eq 'First seen')
  913.     {
  914.         return scalar localtime($network->{$bssid}{'firsttime'});
  915.     }
  916.     elsif($field eq 'Last seen')
  917.     {
  918.         return scalar localtime($network->{$bssid}{'lasttime'});
  919.     }
  920.     elsif($field eq 'Clients')
  921.     {
  922.         my @clients = keys %{$network->{$bssid}{'client'}};
  923.         return $#{clients} + 1;
  924.     }
  925.     elsif($field eq 'Type')
  926.     {
  927.         if($network->{$bssid}{'type'} == $network_type{'network_ap'})
  928.                 {
  929.                         return 'Access Point (infrastructure)';
  930.                 }
  931.                 elsif($network->{$bssid}{'type'} == $network_type{'network_adhoc'})
  932.                 {
  933.                         return 'Ad-hoc';
  934.                 }
  935.                 elsif($network->{$bssid}{'type'} == $network_type{'network_probe'})
  936.                 {
  937.                         return 'Probe request (searching client)';
  938.                 }
  939.                 elsif($network->{$bssid}{'type'} == $network_type{'network_turbocell'})
  940.                 {
  941.                         return 'Turbocell';
  942.                 }
  943.                 elsif($network->{$bssid}{'type'} == $network_type{'network_data'})
  944.                 {
  945.                         return 'Data (no network control traffic)';
  946.                 }
  947.                 elsif($network->{$bssid}{'type'} == $network_type{'network_remove'})
  948.                 {
  949.                         return 'Network remove request';
  950.                 }
  951.     }
  952.     elsif($field eq 'Channel')
  953.     {
  954.         return $network->{$bssid}{'channel'};
  955.     }
  956.     elsif($field eq 'WEP')
  957.     {
  958.         $network->{$bssid}{'wep'} ? return 'Yes' : return 'No';
  959.     }
  960.     elsif($field eq 'Encryption')
  961.     {
  962.         if($network->{$bssid}{'wep'} == $encryption_type{'encryption_none'})
  963.         {
  964.             return 'None';
  965.         }
  966.  
  967.         my $res = '';
  968.         if($network->{$bssid}{'wep'} & $encryption_type{'encryption_unknown'})
  969.         {
  970.             $res .= 'Unknown ';
  971.         }
  972.         if($network->{$bssid}{'wep'} & $encryption_type{'encryption_wep'})
  973.         {
  974.             $res .= 'WEP ';
  975.         }
  976.         if($network->{$bssid}{'wep'} & $encryption_type{'encryption_layer3'})
  977.         {
  978.             $res .= 'Layer 3 ';
  979.         }
  980.         if($network->{$bssid}{'wep'} & $encryption_type{'encryption_wpa'})
  981.         {
  982.             $res .= 'WPA ';
  983.         }
  984.         if($network->{$bssid}{'wep'} & $encryption_type{'encryption_leap'})
  985.         {
  986.             $res .= 'LEAP ';
  987.         }
  988.         if($network->{$bssid}{'wep'} & $encryption_type{'encryption_ttls'})
  989.         {
  990.             $res .= 'TTLS ';
  991.         }
  992.         if($network->{$bssid}{'wep'} & $encryption_type{'encryption_tls'})
  993.         {
  994.             $res .= 'TLS ';
  995.         }
  996.         if($network->{$bssid}{'wep'} & $encryption_type{'encryption_peap'})
  997.         {
  998.             $res .= 'PEAP ';
  999.         }
  1000.         if($network->{$bssid}{'wep'} & $encryption_type{'encryption_isakmp'})
  1001.         {
  1002.             $res .= 'ISAKMP ';
  1003.         }
  1004.         if($network->{$bssid}{'wep'} & $encryption_type{'encryption_pptp'})
  1005.         {
  1006.             $res .= 'PPTP ';
  1007.         }
  1008.         return substr($res, 0, -1);
  1009.     }
  1010.     elsif($field eq "Decrypted")
  1011.     {
  1012.         return $network->{$bssid}{'decrypted'} ? 'Yes' : 'No';
  1013.     }
  1014.     elsif($field eq 'Beacon')
  1015.     {
  1016.         return $network->{$bssid}{'beaconrate'};
  1017.     }
  1018.     elsif($field eq 'Data packets')
  1019.     {
  1020.         return $network->{$bssid}{'datapackets'};
  1021.     }
  1022.     elsif($field eq 'LLC packets')
  1023.     {
  1024.         return $network->{$bssid}{'llcpackets'};
  1025.     }
  1026.     elsif($field eq 'Crypt packets')
  1027.     {
  1028.         return $network->{$bssid}{'cryptpackets'};
  1029.     }
  1030.     elsif($field eq 'Weak packets')
  1031.     {
  1032.         return $network->{$bssid}{'weakpackets'};
  1033.     }
  1034.     elsif($field eq 'Dupe IV')
  1035.     {
  1036.         return $network->{$bssid}{'dupeivpackets'};
  1037.     }
  1038.     elsif($field eq 'Data')
  1039.     {
  1040.         return $network->{$bssid}{'datasize'} . " bytes";
  1041.     }
  1042.     elsif($field eq 'Power')
  1043.     {
  1044.         return $network->{$bssid}{'signal'} . "/" . $network->{$bssid}{'bestsignal'};
  1045.     }
  1046.     elsif($field eq 'Noise')
  1047.     {
  1048.         return $network->{$bssid}{'noise'} . "/" . $network->{$bssid}{'bestnoise'};
  1049.     }
  1050.     elsif($field eq 'IP Range')
  1051.     {
  1052.         return $network->{$bssid}{'rangeip'};
  1053.     }
  1054.     elsif($field eq 'IP Type')
  1055.     {
  1056.         if($network->{$bssid}{'atype'} == $address_type{'address_none'})
  1057.                 {
  1058.                         return 'None detected';
  1059.                 }
  1060.                 elsif($network->{$bssid}{'atype'} == $address_type{'address_factory'})
  1061.                 {
  1062.                         return 'Factory default';
  1063.                 }
  1064.                 elsif($network->{$bssid}{'atype'} == $address_type{'address_udp'})
  1065.                 {
  1066.                         return 'UDP (' .  $network->{$bssid}{'octets'} . " octets)";
  1067.                 }
  1068.                 elsif($network->{$bssid}{'atype'} == $address_type{'address_arp'})
  1069.                 {
  1070.                         return 'ARP (' .  $network->{$bssid}{'octets'} . " octets)";
  1071.                 }
  1072.                 elsif($network->{$bssid}{'atype'} == $address_type{'address_tcp'})
  1073.                 {
  1074.                         return 'TCP (' .  $network->{$bssid}{'octets'} . " octets)";
  1075.                 }
  1076.                 elsif($network->{$bssid}{'atype'} == $address_type{'address_dhcp'})
  1077.                 {
  1078.                         return 'DHCP';
  1079.                 }
  1080.                 elsif($network->{$bssid}{'atype'} == $address_type{'address_group'})
  1081.                 {
  1082.                         return 'Group (aggregate)';
  1083.                 }
  1084.                 else
  1085.                 {
  1086.                         return 'UNKNOWN';
  1087.                 }
  1088.     }
  1089.     else
  1090.     {
  1091.         return('Not implemented');
  1092.     }
  1093. }
  1094.  
  1095. #
  1096. # Return printable client data
  1097. #
  1098. sub getClientFieldValue
  1099. {
  1100.     my $self = shift;
  1101.     my $bssid = shift;
  1102.     my $mac = shift;
  1103.     my $field = shift;
  1104.  
  1105.     if(!defined $self->{'connection'})
  1106.     {
  1107.         return undef;
  1108.     }
  1109.     my $network = $self->{'connection'}->getNetwork();
  1110.  
  1111.     if($field eq 'MAC')
  1112.     {
  1113.         return $network->{$bssid}{'client'}{$mac}{'mac'};
  1114.     }
  1115.     elsif($field eq 'Type')
  1116.     {
  1117.         if($network->{$bssid}{'client'}{$mac}{'type'} == $client_type{'client_unknown'})
  1118.         {
  1119.             return 'Unknown';
  1120.         }
  1121.         elsif ($network->{$bssid}{'client'}{$mac}{'type'} == $client_type{'client_fromds'})
  1122.         {
  1123.             return 'From Distribution (AP->Wireless)';
  1124.         }
  1125.         elsif ($network->{$bssid}{'client'}{$mac}{'type'} == $client_type{'client_tods'})
  1126.         {
  1127.             return 'To Distribution (Wireless->AP)';
  1128.         }
  1129.         elsif ($network->{$bssid}{'client'}{$mac}{'type'} == $client_type{'client_interds'})
  1130.         {
  1131.             return 'Intra-distribution (AP->AP)';
  1132.         }
  1133.         elsif ($network->{$bssid}{'client'}{$mac}{'type'} == $client_type{'client_established'})
  1134.         {
  1135.             return 'Established (Wireless->AP and AP->Wireless)';
  1136.         }
  1137.         else
  1138.         {
  1139.             return 'Unknown';
  1140.         }
  1141.     }
  1142.     elsif($field eq 'Manufacturer')
  1143.     {
  1144.         my($manuf, $model, $score) = $self->lookupManuf($self->{'clManuf'}, $mac, $network->{$bssid}{'ssid'},
  1145.             $network->{$bssid}{'channel'}, $network->{$bssid}{'wep'}, $network->{$bssid}{'cloaked'}, $network->{$bssid}{'client'}{$mac}{'ip'});
  1146.         return($manuf);
  1147.     }
  1148.     elsif($field eq 'Model')
  1149.     {
  1150.         my($manuf, $model, $score) = $self->lookupManuf($self->{'clManuf'}, $mac, $network->{$bssid}{'ssid'},
  1151.             $network->{$bssid}{'channel'}, $network->{$bssid}{'wep'}, $network->{$bssid}{'cloaked'}, $network->{$bssid}{'client'}{$mac}{'ip'});
  1152.         return($model);
  1153.     }
  1154.     elsif($field eq 'First seen')
  1155.     {
  1156.         return scalar localtime $network->{$bssid}{'client'}{$mac}{'firsttime'};
  1157.     }
  1158.     elsif($field eq 'Last seen')
  1159.     {
  1160.         return scalar localtime $network->{$bssid}{'client'}{$mac}{'lasttime'};
  1161.     }
  1162.     elsif($field eq 'Max rate')
  1163.     {
  1164.         return $network->{$bssid}{'client'}{$mac}{'maxrate'};
  1165.     }
  1166.     elsif($field eq "Max seen")
  1167.     {
  1168.         return $network->{$bssid}{'client'}{$mac}{'maxseenrate'} * 100;
  1169.     }
  1170.     elsif($field eq 'Encoding')
  1171.     {
  1172.         if($network->{$bssid}{'client'}{$mac}{'encodingset'} & (1 << $encoding_type{'encoding_unknown'}))
  1173.         {
  1174.             return 'Unknown';
  1175.         }
  1176.         elsif($network->{$bssid}{'client'}{$mac}{'encodingset'} & (1 << $encoding_type{'encoding_cck'}))
  1177.         {
  1178.             return 'CCK';
  1179.         }
  1180.         elsif($network->{$bssid}{'client'}{$mac}{'encodingset'} & (1 << $encoding_type{'encoding_pbcc'}))
  1181.         {
  1182.             return 'PBCC';
  1183.         }
  1184.         elsif($network->{$bssid}{'client'}{$mac}{'encodingset'} & (1 << $encoding_type{'encoding_ofdm'}))
  1185.         {
  1186.             return 'OFDM';
  1187.         }
  1188.         else
  1189.         {
  1190.             return 'Unknown';
  1191.         }
  1192.     }
  1193.     elsif($field eq 'Channel')
  1194.     {
  1195.         return $network->{$bssid}{'channel'};
  1196.     }
  1197.     elsif($field eq 'WEP')
  1198.     {
  1199.         $network->{$bssid}{'client'}{$mac}{'wep'} ? return 'Yes' : return 'No';
  1200.     }
  1201.     elsif($field eq "Decrypted")
  1202.     {
  1203.         return $network->{$bssid}{'client'}{$mac}{'decrypted'} ? 'Yes' : 'No';
  1204.     }
  1205.     elsif($field eq 'IP')
  1206.     {
  1207.         $network->{$bssid}{'client'}{$mac}{'ip'};
  1208.     }
  1209.     elsif($field eq 'Data packets')
  1210.     {
  1211.         $network->{$bssid}{'client'}{$mac}{'datapackets'};
  1212.     }
  1213.     elsif($field eq 'Crypt packets')
  1214.     {
  1215.         $network->{$bssid}{'client'}{$mac}{'cryptpackets'};
  1216.     }
  1217.     elsif($field eq 'Weak packets')
  1218.     {
  1219.         $network->{$bssid}{'client'}{$mac}{'weakpackets'};
  1220.     }
  1221.     elsif($field eq 'Data')
  1222.     {
  1223.         $network->{$bssid}{'client'}{$mac}{'datasize'} . " bytes";
  1224.     }
  1225.     elsif($field eq 'Power')
  1226.     {
  1227.         return $network->{$bssid}{'client'}{$mac}{'signal'} . "/" . $network->{$bssid}{'client'}{$mac}{'bestsignal'};
  1228.     }
  1229.     elsif($field eq 'Noise')
  1230.     {
  1231.         return $network->{$bssid}{'client'}{$mac}{'noise'} . "/" . $network->{$bssid}{'client'}{$mac}{'bestnoise'};
  1232.     }
  1233.     else
  1234.     {
  1235.         return('Not implemented');
  1236.     }
  1237. }
  1238.  
  1239. #
  1240. # Return color for a network
  1241. #
  1242. sub getNetworkColor
  1243. {
  1244.     my $self = shift;
  1245.     my $bssid = shift;
  1246.  
  1247.     if(!defined $self->{'connection'})
  1248.     {
  1249.         return undef;
  1250.     }
  1251.     my $network = $self->{'connection'}->getNetwork();
  1252.  
  1253.     if(!$network->{$bssid}{'wep'})
  1254.     {
  1255.         my($manuf, $model, $score) = $self->lookupManuf($self->{'apManuf'}, $bssid, $network->{$bssid}{'ssid'},
  1256.             $network->{$bssid}{'channel'}, $network->{$bssid}{'wep'}, $network->{$bssid}{'cloaked'}, $network->{$bssid}{'rangeip'});
  1257.         if($score == $max_manuf_score)
  1258.         {
  1259.             return($self->{'colorRed'});
  1260.         }
  1261.         return($self->{'colorYellow'});
  1262.     }
  1263.     else
  1264.     {
  1265.         return($self->{'colorGreen'});
  1266.     }
  1267. }
  1268.  
  1269. #
  1270. # Get network pixmap
  1271. #
  1272. sub getNetworkPixmapName
  1273. {
  1274.     my $self = shift;
  1275.     my $bssid = shift;
  1276.  
  1277.     if(!defined $self->{'connection'})
  1278.     {
  1279.         return undef;
  1280.     }
  1281.     my $network = $self->{'connection'}->getNetwork();
  1282.  
  1283.     $self->buildPixmaps();
  1284.     my $pixmapName;
  1285.  
  1286.     if($network->{$bssid}{'type'} == $network_type{'network_ap'})
  1287.         {
  1288.         $pixmapName = 'networkAP';
  1289.     }
  1290.     elsif($network->{$bssid}{'type'} == $network_type{'network_adhoc'})
  1291.     {
  1292.         $pixmapName = 'networkAdhoc';
  1293.     }
  1294.     elsif($network->{$bssid}{'type'} == $network_type{'network_probe'})
  1295.     {
  1296.         $pixmapName = 'networkProbe';
  1297.     }
  1298.     elsif($network->{$bssid}{'type'} == $network_type{'network_turbocell'})
  1299.     {
  1300.         $pixmapName = 'networkTurbocell';
  1301.     }
  1302.     elsif($network->{$bssid}{'type'} == $network_type{'network_data'})
  1303.     {
  1304.         $pixmapName = 'networkData';
  1305.       }
  1306.     elsif($network->{$bssid}{'type'} == $network_type{'network_remove'})
  1307.     {
  1308.         $pixmapName = 'networkRemove';
  1309.     }
  1310.  
  1311.     if(time() - $network->{$bssid}{'lasttime'} < $activeTimeout)
  1312.     {
  1313.         $pixmapName .= 'Active';
  1314.     }
  1315.  
  1316.     return $pixmapName;
  1317. }
  1318.  
  1319. #
  1320. # Get client pixmap
  1321. #
  1322. sub getClientPixmapName
  1323. {
  1324.     my $self = shift;
  1325.     my $bssid = shift;
  1326.     my $mac = shift;
  1327.  
  1328.     if(!defined $self->{'connection'})
  1329.     {
  1330.         return undef;
  1331.     }
  1332.     my $network = $self->{'connection'}->getNetwork();
  1333.  
  1334.     $self->buildPixmaps();
  1335.     my $pixmapName;
  1336.  
  1337.     if($network->{$bssid}{'client'}{$mac}{'type'} == $client_type{'client_unknown'})
  1338.     {
  1339.         $pixmapName = 'clientUnknown';
  1340.     }
  1341.     elsif ($network->{$bssid}{'client'}{$mac}{'type'} == $client_type{'client_fromds'})
  1342.     {
  1343.         $pixmapName = 'clientFromDist';
  1344.     }
  1345.     elsif ($network->{$bssid}{'client'}{$mac}{'type'} == $client_type{'client_tods'})
  1346.     {
  1347.         $pixmapName = 'clientToDist';
  1348.     }
  1349.     elsif ($network->{$bssid}{'client'}{$mac}{'type'} == $client_type{'client_interds'})
  1350.     {
  1351.         $pixmapName = 'clientIntraDist';
  1352.     }
  1353.     elsif ($network->{$bssid}{'client'}{$mac}{'type'} == $client_type{'client_established'})
  1354.     {
  1355.         $pixmapName = 'clientEstablished';
  1356.     }
  1357.  
  1358.     if(time() - $network->{$bssid}{'client'}{$mac}{'lasttime'} < $activeTimeout)
  1359.     {
  1360.         $pixmapName .= 'Active';
  1361.     }
  1362.  
  1363.     return $pixmapName;
  1364. }
  1365.  
  1366. #
  1367. # Build pixmaps if not yet built
  1368. #
  1369. sub buildPixmaps
  1370. {
  1371.     my $self = shift;
  1372.     if(!$self->{'pixmapsBuilt'})
  1373.     {
  1374.         for my $pixmap (qw(networkAP networkAdhoc networkProbe networkTurbocell networkData networkRemove 
  1375.             clientFromDist clientToDist clientIntraDist clientEstablished clientUnknown
  1376.             networkAPActive networkAdhocActive networkProbeActive networkTurbocellActive networkDataActive networkRemoveActive
  1377.             clientFromDistActive clientToDistActive clientIntraDistActive clientEstablishedActive clientUnknownActive))
  1378.         {
  1379.             ($self->{'pixmap'}{$pixmap}{'pixmap'}, $self->{'pixmap'}{$pixmap}{'mask'}) =
  1380.                 Gtk::Gdk::Pixmap->create_from_xpm($self->{'ctree'}->window(),
  1381.                 Gtk::Widget->get_default_style()->bg('normal'),
  1382.                 $self->{'gKismetApplication'}{'path'}{'xpm'} . '/' . $pixmap . '.xpm');
  1383.         }
  1384.         $self->{'pixmapsBuilt'} = $true;
  1385.     }
  1386. }
  1387.  
  1388. 1;
  1389.